from app.extensions import db
import werkzeug.security as ws


class User(db.Model):
    user_id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(50), unique=True, nullable=False)
    password_hash = db.Column(db.String(255), nullable=False)
    role = db.Column(db.String(50), nullable=False)
    email = db.Column(db.String(100))

    def set_password(self, password):
        self.password_hash = ws.generate_password_hash(password)

    def check_password(self, password):
        return ws.check_password_hash(self.password_hash, password)
